package model.resource;

import java.util.Random;

import model.map.GameMap;
import model.mapping.ResourceMapping;

public class MapResourcePopulator
{
	private final int RENEWAL_RATE = 5;
	private final int MAX_FOOD = 5000;
	private final int MAX_ORE = 5000;
	private final int MAX_ENERGY = 5000;
	
	private RenewableResourceManager renewManager;
	
	private static ResourceMapping resourceMapping = ResourceMapping.getResourceMapping();
	private static MapResourcePopulator mrp = new MapResourcePopulator();
	
	private MapResourcePopulator()
	{
		renewManager = new RenewableResourceManager(RENEWAL_RATE);
	}
	
	public RenewableResourceManager getResourceManager()
	{
		return renewManager;
	}
	
	public void populate(GameMap map)
	{
		RenewableResource tempFood;
		NonRenewableResource tempEnergy, tempOre;
		
		Random rnd = new Random();
		
		for (int i = 0; i < map.getMapLength(); i++)
		{
			for (int j = 0; j < map.getMapHeight(); j++)
			{
				tempFood = new RenewableResource("food", rnd.nextInt(MAX_FOOD));
				tempEnergy = new NonRenewableResource("energy", rnd.nextInt(MAX_ENERGY));
				tempOre = new NonRenewableResource("ore", rnd.nextInt(MAX_ORE));
				
				ResourceTriplet temp = new ResourceTriplet(tempFood, tempOre, tempEnergy);
				resourceMapping.addResource(map.getTileAt(i, j), temp);
				
				renewManager.addResource(tempFood);
			}
		}
	}
	
	public static MapResourcePopulator getResourcePopulator()
	{
		return mrp;
	}
}
